package com.jq.aution.service.impl;

import com.jq.aution.mapper.ProductInfoMapper;
import com.jq.aution.model.ProductInfo;
import com.jq.aution.model.ProductInfoExample;
import com.jq.aution.service.ProductInfoService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ProductInfoServiceImpl implements ProductInfoService {
    private static final Logger LOGGER = LoggerFactory.getLogger(ProductInfoServiceImpl.class);

    @Autowired
    ProductInfoMapper productInfoMapper;

    @Override
    public boolean update(ProductInfo productInfo) {
        if(productInfoMapper.updateByPrimaryKeySelective(productInfo)==1){
            return true;
        }
        return false;
    }

    @Override
    public List<ProductInfo> getList() {
        ProductInfoExample example=new ProductInfoExample();
        return productInfoMapper.selectByExample(example);
    }

    @Override
    public ProductInfo loadProductById(Integer id) {
        ProductInfoExample example=new ProductInfoExample();
        example.createCriteria().andProductIdEqualTo(id);
        ProductInfo productInfo=null;
        try {
            productInfo=productInfoMapper.selectByExample(example).get(0);
        }catch (Exception e){
            LOGGER.error("获取商品详细信息出错"+e.getMessage());
        }
        return productInfo;
    }
}
